package Demo523;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;

public class LoginDemo {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Connection connection = SqlConnection.getCon();
        Scanner scanner = new Scanner(System.in);//从挑盘输入
        System.out.println("请输入用户名");
        String username = scanner.next();
        System.out.println("请输入密码");
        String password = scanner.next();
        String sql = "select * from users where username=? and password=?";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, username);
        preparedStatement.setString(2,password);
        ResultSet resultSet = preparedStatement.executeQuery();
        if (resultSet.next()) {
            String name = resultSet.getString("username");
            String pwd = resultSet.getString("password");
//输入用户名和密码
            System.out.println("用户名是：" + name);
            System.out.println("密码是：" + pwd);
            System.out.println("登录成功");
        }
else
            System.out.println("登录失败");

        }
    }